package com.jollychic.www.roomdatebasedemo.database;

import android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.TypeConverters;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;

import com.jollychic.www.roomdatebasedemo.convert.Converts;
import com.jollychic.www.roomdatebasedemo.dao.IDrinkDao;
import com.jollychic.www.roomdatebasedemo.dao.IGoodsDao;
import com.jollychic.www.roomdatebasedemo.dao.IStoreDao;
import com.jollychic.www.roomdatebasedemo.model.DrinksEntity;
import com.jollychic.www.roomdatebasedemo.model.GoodEntity;
import com.jollychic.www.roomdatebasedemo.model.StoreEntity;

/**
 * desc:  <br/>
 * author: 李超杰 <br/>
 * time: 2018/4/20 0020 20:46 <br/>
 * since: V 6.1X <br/>
 */
@Database(entities = {StoreEntity.class, GoodEntity.class, DrinksEntity.class}, version = 2)
@TypeConverters({Converts.class})
public abstract class GlobalDateBase extends RoomDatabase {

    private static final String DB_TABLE = "Room.db";


    private static GlobalDateBase INSTANCE;

    public static synchronized GlobalDateBase getInstance(Context context) {
        if (INSTANCE == null) {
            INSTANCE = create(context);
        }
        return INSTANCE;
    }

    private static GlobalDateBase create(Context context) {
        return Room.databaseBuilder(context, GlobalDateBase.class, DB_TABLE)
                .addCallback(new Callback() {
                    @Override
                    public void onCreate(@NonNull SupportSQLiteDatabase db) {
                        super.onCreate(db);

                    }

                    @Override
                    public void onOpen(@NonNull SupportSQLiteDatabase db) {
                        super.onOpen(db);

                    }
                })
                .allowMainThreadQueries()
                .addMigrations(Migrations.MIGRATION_1_2)
                .fallbackToDestructiveMigration()
                .build();
    }

    /**
     * 获取店铺dao
     *
     * @return
     */
    public abstract IStoreDao storeDao();

    /**
     * 获取商品dao
     *
     * @return
     */
    public abstract IGoodsDao goodsDao();

    public abstract IDrinkDao drinkDao();


//    public void get(){
//
//        final SQLiteOpenHelper sqLiteOpenHelper = new SQLiteOpenHelper(null, "", null, 1) {
//
//            @Override
//            public void onCreate(SQLiteDatabase sqLiteDatabase) {
//
//            }
//
//            @Override
//            public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
//
//            }
//        };
//
//        final SQLiteDatabase database= sqLiteOpenHelper.getWritableDatabase();
//
//        final ContentValues contentValues = new ContentValues();
//        contentValues.put();
//        contentValues.put();
//        contentValues.put();
//        contentValues.put();
//        database.insert(contentValues);
//        database.compileStatement("input your sql");
//        database.execSQL();
//
//
//
//    }

}
